package org.aeon.utils;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

/**
 * @author: MissingAeon
 * @date: 2024/1/27 13:21
 * @description:
 */
public class UUIDUtils {
    public static String generateUniqueId(String username, String password) {
        // 将指定的字符串转换为字节数组
        byte[] usernameB = username.getBytes(StandardCharsets.UTF_8);
        byte[] passwordB = password.getBytes(StandardCharsets.UTF_8);

        // 获取当前时间的毫秒数的字节数组
        byte[] currentTimeB = String.valueOf(System.currentTimeMillis()).getBytes(StandardCharsets.UTF_8);

        // 合并两个字节数组
        byte[] combinedBytes = new byte[usernameB.length + passwordB.length + currentTimeB.length];
        System.arraycopy(usernameB, 0, combinedBytes, 0, usernameB.length);
        System.arraycopy(passwordB, 0, combinedBytes, usernameB.length, passwordB.length);
        System.arraycopy(currentTimeB, 0, combinedBytes, usernameB.length + passwordB.length, currentTimeB.length);

        // 使用nameUUIDFromBytes生成UUID
        return UUID.nameUUIDFromBytes(combinedBytes).toString();
    }
}
